package com.ymatou.iapi.userservice.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.UserIdMappingMobileDtoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.UserIdMappingMobileDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 手机号批量查询uid FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_UserIdMappingMobileDto {
	private static UserIdMappingMobileDtoBean umb;
	private static UserIdMappingMobileDtoCall umc;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("手机号批量查询uid");
	}

	@Before
	public void caseUp() {
		umb = new UserIdMappingMobileDtoBean();
		umc = new UserIdMappingMobileDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(umc.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserIdMappingMobileDto_001() {
		Logger.start(true,"手机号批量查询uid成功");
		try {
			
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
			List<String> MobileArray = new ArrayList<String>();
			MobileArray.add(phone);
			umb.setMobileArray(MobileArray);
			umb.setQuerySize(100);
			umc.setData(umb);
			umc.callService();
			Logger.verifyEquals(ECode.SUCCESS, umc.getResponseCode(), "验证Code");
			Logger.verifyEquals(true, umc.getSuccess(), "验证Success");
			Logger.verifyEquals(uid.toString(), umc.getResult().get(phone).toString(),
					"验证UserId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserIdMappingMobileDto_002() {
		Logger.start(true,"不输入手机号,手机号批量查询uid失败");
		try {
			// Map m=new UserCallService().registerByMobile();
			List<String> MobileArray = new ArrayList<String>();
			// MobileArray.add(m.get("Phone").toString());
			umb.setMobileArray(MobileArray);
			umb.setQuerySize(100);
			umc.setData(umb);
			umc.callService();
			Logger.verifyEquals("100", umc.getResponseCode(), "验证Code");
			Logger.verifyEquals(false, umc.getSuccess(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserIdMappingMobileDto_003() {
		Logger.start(true,"错误手机号,手机号批量查询uid没有结果");
		try {
			List<String> MobileArray = new ArrayList<String>();
			MobileArray.add(TestDataManager.getPhoneNum());
			umb.setMobileArray(MobileArray);
			umb.setQuerySize(100);
			umc.setData(umb);
			umc.callService();
			Logger.verifyEquals(ECode.SUCCESS, umc.getResponseCode(), "验证Code");
			Logger.verifyEquals(true, umc.getSuccess(), "验证Success");
//			Logger.verifyEquals("{}", umc.getResult().toString(), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
//	@Ignore
	//批量查询数量太多，遇到有修改此接口时单独跑
	public void Tc_UserIdMappingMobileDto_004() {
		Logger.start(true,"手机号批量查询多个uid成功");
		try {
			List<String> MobileArray = new ArrayList<String>();
			List<Map> mlist = new ArrayList<Map>();
			for (int i = 0; i < 2; i++) {
				Map m=new HashMap<>();
				CreateUserReq cur=new CreateUserReq();
				cur=JUserCallService.initCreateUserBean(cur);
				Integer uid = JUserCallService.createUserCall(cur);
				String phone=cur.getMobile();
				m.put("phone", phone);
				m.put("userid", uid);
				mlist.add(m);
				MobileArray.add(phone);
			}
			umb.setMobileArray(MobileArray);
			umb.setQuerySize(100);
			umc.setData(umb);
			umc.callService();
			Logger.verifyEquals(ECode.SUCCESS, umc.getResponseCode(), "验证Code");
			Logger.verifyEquals(true, umc.getSuccess(), "验证Success");
			for (Map map : mlist) {
				Logger.verifyEquals(map.get("userid").toString(), umc.getResult().get(map.get("phone").toString())
						.toString(), "验证UserId");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}